package proxy05;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Date;

public class HandlerImpl implements InvocationHandler {
    private LaoWang lw = new LaoWang();
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        long startTime = new Date().getTime();

        method.invoke(lw);//如果当前代理类对象调用的是eat()
        //最终转调过来,method.invoke(lw) => lw.eat();
        //如果当前代理类对象调用的是play()
        //最终转调过来,method.invoke(lw) => lw.play();
        //如果当前代理类对象调用的是sleep()
        //最终转调过来,method.invoke(lw) => lw.sleep();

        long endTime = new Date().getTime();
        System.out.println("吃饭需要的时间:"+ (endTime-startTime));

        return null;
    }
}
